<?

include "kernel.php";


$all_pilots_r = mysql_query("select pilotid from finalpilots order by pilotid");

while ($pilot = mysql_fetch_assoc($all_pilots_r)) {

	$pilot = $pilot[pilotid];

	$check_sortie_r = mysql_query("
    	select
			max(UNIX_TIMESTAMP(s.endtime)) as endtime
        from
        	sorties as s
        where
        	pilotid = '$pilot'
            	and
		    (
            	(UNIX_TIMESTAMP(s.endtime)-UNIX_TIMESTAMP(s.starttime))>=60*15
					or
        		(s.eSAir+s.eTank+s.eCar+s.eArt+s.eAaa+s.eWag+s.eShip)>0
            		or
        		s.SortieEND<>'TKON'
                	or
                s.eAir>0
            )
        		and
        	SortieEND != 'MIA'
        group by
        	s.pilotid");


    $check_sortie = mysql_fetch_assoc($check_sortie_r);


    $visible=0;
    if (time() - $check_sortie[endtime] <= 5*24*3600)
    	$visible=1;
    echo "Visible:$visible";

    $q = mysql_query("
    update
    	finalpilots
    set
        visible='$visible'
    where
    	pilotid='$pilot'
    ");

}

?>